<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>
  <head>
    <base href="<%=basePath%>">  
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
	<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>  
	<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
	<script>		
			var adminName=true;//设置全局变量   提交验证时候用  初始值设置true  是因为更改信息本就应该是符合规则的  所以直接提交是可以的
			var password=true;
			var passwordchong = true;
			var note=true;
			$(function(){
				 $("input[type=text],textarea").focus(function(){
					  $(this).addClass("input_focus");
					}).blur(function(){
							$(this).removeClass("input_focus");
					});

				$(".form_btn").hover(function(){
						$(this).css("color","red").css("background","#6FB2DB");
					},
					
					function(){
						$(this).css("color","#295568").css("background","#BAD9E3");
					});	
				
				$("#adminName").blur(function (){
					var a = $(this);
					var name=$(this).val();
					var reg=/^[0-9A-Za-z]{4,15}$/g;
					if(reg.test(name)){
						$.ajax({
							url:"AdminServlet.do",
							type:"post",
							data:{adminName:a.val(),flag:"checkAdminName"},
							success:function(AdminName){
								if(AdminName!=""){
									$("#"+a[0].id +"_msg").html(AdminName).removeClass().addClass("validate_error");
									adminName=false;
								}else{
									$("#"+a[0].id +"_msg").html("√").removeClass().addClass("validate_ok");
									adminName=true;
								}
							}
						});
					}else{
						$("#"+a[0].id +"_msg").html("用户格式错误").removeClass().addClass("validate_error");
						adminName=false;
					}
				});
				$("#password").blur(function (){
					var passWord=$(this).val();
					var reg=/^[0-9A-Za-z]{6,20}$/g;
					if(reg.test(passWord)){
						$("#"+$(this)[0].id+"_msg").html("√").removeClass().addClass("validate_ok");
						password=true;
					}else{
						$("#"+$(this)[0].id+"_msg").html("密码格式错误").removeClass().addClass("validate_error");
						password=false;
					}
					
				});
				$("#pwdconfirm").blur(function (){
						var a = $("#password").val();
						var b = $(this).val();
						if(a==b){
							$("#"+$(this)[0].id+"_msg").html("√").removeClass().addClass("validate_ok");
							passwordchong =  true;
						}else{
							$("#"+$(this)[0].id+"_msg").html("与密码不完全相同").removeClass().addClass("validate_error");
							passwordchong =  false;
						}
						if(a==""){
						$("#"+$(this)[0].id+"_msg").html("请填写密码").removeClass().addClass("validate_error");
						passwordchong = false;
					}
				});
				$(".txtarea").blur(function (){
					var a = $(this).val();
					if(a!=""){
						$("#note_msg").html("√").removeClass().addClass("validate_ok");
						note =  true;
					}else{
						$("#note_msg").html("备注不可以为空").removeClass().addClass("validate_error");
						note = false;
					}
			});
				$("input[type=reset]").click(function(){
					window.location.href="admin/admin_info.jsp";
				});
				$("input[type=submit]").click(function(){
					var result=true;
					
					if(adminName==false){
						$("#adminName").blur();
						result = false;
					}
					if(password==false){
						$("#password").blur();
						result = false;
					} 
					if(passwordchong==false){
						$("#pwdconfirm").blur();
						result = false;
					}
					if(note==false){
						$(".txtarea").blur();
						result = false;
					}
					var session = '${admin_session}';
					if(session!=""){
						if(result==true){
								if(confirm("确认提交吗")){
									var id='${adminInfo.id}';
									$.ajax({
										url:"AdminServlet.do",
										type:"post",
										data:{id:id,adminName:$("#adminName").val(),flag:"updateAdmin",password:$("#password").val(),note:$(".txtarea").val()},
										success:function(data){
											$("#result_msg").html(data).removeClass().addClass("validate_ok");
										}
									});
							}
						}else{
							$("#result_msg").html("请正确填写信息后提交").removeClass().addClass("validate_error");
						}
					}else{
						window.location.href="login.jsp";
					}
				});
			});		
			
	</script>
  </head>
  
  <body>
    <div class ="div_title">
		 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理员修改</span></div>
	 </div>
				 
		 <table class="edit_table" >
		 		<tr>
		 			 	<td class="td_info">用户账号:</td>	
		 			 	<td class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="adminName" name="adminName" value="${adminInfo.adminName }"/> 
		 			 	</td>   
		 			 	<td>
		 			 		<label class="validate_info" id="adminName_msg" >4-15位；只限数字(0-9)和英文(a-z),不区分大小写</label>
		 			 	</td> 
		 		</tr>
		 			<tr>
		 				<td class="td_info">用户密码:</td>	
		 				<td>
		 					<input type="password"  class="txtbox"  name="password"  id="password" value="${adminInfo.password }"/>
		 				</td> 
		 				<td><label  class="validate_info" id="password_msg" >数字或英文,6-20位</label></td>	
		 		</tr>
		 			<tr>
		 				<td class="td_info">重复密码:</td>	
		 				<td><input type="password" class="txtbox" id="pwdconfirm"  value="${adminInfo.password }"/> 
		 				</td>
		 				<td><label  class="validate_info"  id="pwdconfirm_msg">请重复输入密码</label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info">备注信息:</td>	
		 			<td><textarea rows="4" cols="27" name="note" class="txtarea" >${adminInfo.note }</textarea> </td>	
		 			<td><label id="note_msg"></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td> 
		 			<input class="form_btn" type="submit" value="提交" /> 
		 			<input type="reset"  class="form_btn" value="重置" /> </td>	
		 			<td>
		 				<label id="result_msg" class="result_msg"></label>
		 			</td>	
		 		</tr>
		</table>
  </body>
</html>